package com.ice.body.business.controller;
import com.ice.base.result.AjaxResult;
import com.ice.body.business.model.RecordCabinet;
import com.ice.body.business.service.RecordCabinetService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import com.ice.base.controller.BaseController;
import org.slf4j.Logger;
import com.github.pagehelper.PageHelper;
import org.springframework.util.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.ice.base.result.ResponseResult;
import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2022-10-24
 * Time: 10:13
 */
@RestController
@Api(tags = "柜子上传记录")
public class RecordCabinetController extends BaseController{
    //---------------------------柜子上传记录-----------------------start
    @Resource
    private RecordCabinetService recordCabinetService;
    
    @ApiOperation(value = "柜子上传记录-新增")
    @PostMapping("/api/RecordCabinet/insert")
    public AjaxResult<RecordCabinet> insert_RecordCabinet(RecordCabinet model) {
        AjaxResult r = AjaxResult.success();

        try{
            recordCabinetService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = AjaxResult.error();
        }
        return r;
    }

    @ApiOperation(value = "柜子上传记录-删除")
    @PostMapping("/api/RecordCabinet/deleteById")
    public AjaxResult<RecordCabinet>  deleteById_RecordCabinet(@RequestParam("id") String id) {
        AjaxResult r = AjaxResult.success();
        try{
            Integer count =recordCabinetService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = AjaxResult.error();
        }
        return r;
    }

    @ApiOperation(value = "柜子上传记录-更新")
    @PostMapping("/api/RecordCabinet/updateById")
    public AjaxResult<RecordCabinet> update_RecordCabinet(RecordCabinet model) {
        try{
            Integer count =recordCabinetService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();
        }
        return AjaxResult.success();
    }

    @ApiOperation(value = "柜子上传记录-查询一个")
    @PostMapping("/api/RecordCabinet/selectById")
    public AjaxResult<RecordCabinet> selectById_RecordCabinet(@RequestParam("id") String id) {
        AjaxResult r = AjaxResult.success();
        try{
           RecordCabinet model = recordCabinetService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "柜子上传记录-查询多个")
    @PostMapping("/api/RecordCabinet/selectAll")
    public AjaxResult<RecordCabinet> selectList_RecordCabinet(RecordCabinet model) {
        AjaxResult r = AjaxResult.success();
        try{
           List<RecordCabinet> list = recordCabinetService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "柜子上传记录-查询分页")
    @PostMapping("/api/RecordCabinet/selectListByPageHelper")
    public AjaxResult<RecordCabinet> selectListByPageHelper_RecordCabinet(@RequestParam(name = "pageSize") Integer pageSize,
                                                         @RequestParam(name = "pageNum") Integer pageNum,
                                                         RecordCabinet model){
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
           list = recordCabinetService.selectListByModel(model);
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------柜子上传记录-----------------------end
}
